package com.chenwy.example.learning;

import java.util.*;

public class TTTTT {

    /**
     * 直接暴力枚举
     * 1~9 的数字可以组成 3 个 3 位数，设为：A,B,C, 现在要求满足如下关系：
     * B = 2 * A
     * C = 3 * A
     * 请你写出 A 的所有可能答案，数字间用空格分开，数字按升序排列
     */
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        List<Integer> digits = Arrays.asList(1,2,3,4,5,6,7,8,9);
        List<Integer> result = new ArrayList<>();
        for(int i = 1; i <= 3 ;i ++){
            for(int j = 1; j <= 9 ;j ++){
                for(int k = 1; k <= 9; k++){
                    if(i != j && j != k && i != k){
                        int A = i * 100 + j * 10 + k;
                        int B = 2 * A,C = 3 * A;
                        int h1 = B / 100,t1 = B % 100 / 10,g1 = B % 100 % 10;
                        int h2 = C / 100,t2 = C % 100 / 10,g2 = C % 100 % 10;
                        Set<Integer> set = new HashSet<>();
                        set.addAll(Arrays.asList(i,j,k,h1,t1,g1,h2,t2,g2));
                        if(set.size() == 9
                                && digits.contains(h1) && digits.contains(t1) && digits.contains(g1)
                                && digits.contains(h2) && digits.contains(t2) && digits.contains(g2)){
                            result.add(A);
                        }
                    }
                }
            }
        }
        for(int i = 0 ; i < result.size(); i++){
            System.out.print(result.get(i) + " ");
        }
        System.out.println();
        long end = System.currentTimeMillis();
        System.out.println("耗时" + (end - start) + "ms");
    }
}
